<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/page/common/common_header.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改值别</title>

<script src='${baseURL }/js/jquery.min.js'></script>
<script src='${baseURL }/js/common/addTab.js'></script>
<script src='${baseURL }/js/common/commonForm.js'></script>

<script type="text/javascript" src="http://10.0.250.52/uidev/package/js/itcui.dev.js"></script>
<link rel="stylesheet" type="text/css" href="http://10.0.250.52/uidev/package/css/itcui.dev.css" media="all"/>
<script type="text/javascript" src="http://10.0.250.52/uidev/package/source/thirdparty/js/jquery.validate.js"></script>

<!-- toolbar css  -->
<link rel="stylesheet" type="text/css" href="${baseURL }/css/base.css"
	media="all" />

<script>
	var fields = [
				{title : "id", id : "id", rules : {required:true}},
				{title : "值别编号", id : "num", rules : {required:true}, linebreak:true},
	  			{title : "值别名称", id : "name",rules : {required:true}, linebreak:true},
	  			{title : "排序", id : "sortType",rules : {required:true}, linebreak:true},
	  			{title : "部门", id : "deptId",rules : {required:true},linebreak:true,
	                  type : "combobox",
	                  data : [
	                      ["1","运行值长排班"],
	                      ["2","运行值班员排班"],
	                      ["3","经理排班"],
	                      ["4","船闸排班"]
	                  ]	
	  			},
	  			{title : "站点", id : "siteId",rules : {required:true},linebreak:true,
	  				 type : "combobox",
	                  data : [
	                      ["1","长湖发电有限公司"],
	                      ["2","长潭发电有限公司"],
	                      ["3","枫树坝发电有限公司"]
	                  ]		
	  			},
	  		];
	//重置插入表单
	function resetForm(){
		var data = {
				"id" : "",
				"num" : "",
				"name" : "",
				"sortType" : "",
				"deptId":"1",
				"siteId":"1"
			};
			$("#autoform").ITC_Form("loaddata",data);
	}
	//初始化表单
	function initForm( rowData ){
		var data = {
				"id" : rowData.id,
				"num" : rowData.num,
				"name" : rowData.name,
				"sortType" : rowData.sortType,
				"deptId":rowData.deptId,
				"siteId":rowData.siteId
			};
			$("#autoform").ITC_Form("loaddata",data);
	}
	
	$(document).ready(function() {
		
		$("#autoform").ITC_Form({validate:true,fixLabelWidth:true},fields);
		var rowData = '<%=request.getParameter("rowData") %>';
		rowData = JSON.parse(decodeURI( rowData ) );
		
		initForm( rowData );
		
		$( "#updateButton" ).click(function(){
			var formData = getFormData( "autoform" );
			var url = "${baseURL}/duty/updateDuty.do?formData=" +  encodeURI( formData );
			$.ajax({
				url : url,
				type : 'post',
				dataType : "json",
				success : function(data) {
					if( data.result == "success" ){
						alert( "修改成功 ！");
					}else{
						alert( "修改失败 ！");
					}
					
				}
			});
		});
		
		$( "#deleteButton" ).click(function(){
			var formData = getFormData( "autoform" );
			var url = "${baseURL}/duty/deleteDuty.do?formData=" +  encodeURI( formData );
			$.ajax({
				url : url,
				type : 'post',
				dataType : "json",
				success : function(data) {
					if( data.result == "success" ){
						alert( "删除成功 ！");
						closeTab();
					}else{
						alert( "删除失败 ！");
					}
					
				}
			});
		});
		
	});
		
</script>

</head>
<body class="ml12 mr12 mt12">
	<div id="content">
		<div class="toolbar" style="border-bottom: #5aa3d6 1px solid">
			<div class="row btn-group-sm">
					<button type="button" class="btn btn-default" onclick="closeTab()">关闭</button>
					<button type="button" class="btn btn-success" id="deleteButton">删除</button>
					<button type="button" class="btn btn-success" id="updateButton">修改</button>
			</div>
		</div>
	<form id="autoform" class="autoform">
	</form>
	</div>
</body>
</html>